using UnityEngine;
using System.Collections;

[RequireComponent (typeof (NetworkView))]
public class NID : MonoBehaviour {
	public static int unassigned = -1;
	private int id = unassigned;
	
	public void initalise() {
		if (id == unassigned) {
			if (Network.isServer) {
				id = IDManager.inst().add(networkView.viewID);
				networkView.RPC("rpcAssignId", RPCMode.Others, id);
			}
		}
	}
	
	// Use this for initialization
	void Start () {
		initalise();
	}
	
	// Called by the server to assign an id to this NID.
	[RPC]
	private void rpcAssignId(int id) {
		IDManager.inst().add(id, networkView.viewID);
		this.id = id;
	}
	
	// Returns the unique id of this NID.
	public int getId() {
		return id;
	}
}